package redis

import (
	"context"
	"fmt"
	"time"
)

const (
	USER_INCREASE             = "user:total:increase"
	USER_INCREASE_BIND_BIKE   = "user:bind_increase"
	USER_INCREASE_UNBIND_BIKE = "user:unbind_increase"
	USER_COMPLAIN             = "user:complain"
	USER_ACTIVE               = "ebike:auth:user:active"
)

var UserBindBikeCache = &userBindBike{}
var UserUnbindBike = &userUnbindBike{}
var UserComplain = &userComplain{}
var UserActive = &userActive{}
var UserIncrease = &user{}

type user struct {
}
type userBindBike struct {
}
type userUnbindBike struct {
}
type userComplain struct {
}
type userActive struct {
}

func (e *userBindBike) AddOneDay(ctx context.Context, key time.Time, count int64) (int64, error) {
	ketStr := key.Format("2006-01")
	return DashboardCache.AddOneDayCount(ctx, USER_INCREASE_BIND_BIKE, ketStr, count)

}
func (e *userBindBike) GetOneDay(ctx context.Context, key time.Time) (int64, error) {
	keyStr := key.Format("2006-01")
	dayOfMonth := key.Day()
	// 月份天数都是从1开始的，list从0开始
	return DashboardCache.GetOneDayCount(ctx, USER_INCREASE_BIND_BIKE, keyStr, int64(dayOfMonth-1))
}

func (e *userBindBike) AddThirtyDays(ctx context.Context, key time.Time, counts []int64) (int64, error) {
	keyStr := key.Format("2006-01")
	return DashboardCache.AddBatch(ctx, USER_INCREASE_BIND_BIKE, keyStr, counts...)
}

// GetThirtyDays 获取当前月份所有的天数数据
func (e *userBindBike) GetThirtyDays(ctx context.Context, key time.Time) ([]int64, error) {
	keyStr := key.Format("2006-01")
	return DashboardCache.GetListItems(ctx, USER_INCREASE_BIND_BIKE, keyStr)
}

// AddTwelveMonths 获取当前年所有月份数据
func (e *userBindBike) AddTwelveMonths(ctx context.Context, key time.Time, counts []int64) (int64, error) {
	keyStr := key.Format("2006")
	return DashboardCache.AddBatch(ctx, USER_INCREASE_BIND_BIKE, keyStr, counts...)
}

// GetTwelveMonths 获取当前年所有月份数据
func (e *userBindBike) GetTwelveMonths(ctx context.Context, key time.Time) ([]int64, error) {
	keyStr := key.Format("2006")
	return DashboardCache.GetListItems(ctx, USER_INCREASE_BIND_BIKE, keyStr)
}

// AddFiveYears 获取当前年所有月份数据
func (e *userBindBike) AddFiveYears(ctx context.Context, key time.Time, counts []int64) (int64, error) {
	// 前面4年的数据是已经确定的，年度数据实时计算redis内部缓存数据
	// 往前推4年
	keyStr := fmt.Sprintf("%s:%s", "years", key.Format("2006"))
	return DashboardCache.AddBatch(ctx, USER_INCREASE_BIND_BIKE, keyStr, counts...)
}

func (e *userBindBike) GetFiveYears(ctx context.Context, key time.Time) ([]int64, error) {
	// 按照从远到近依次返回数据，不包含今年的数据，今年数据实时计算
	keyStr := fmt.Sprintf("%s:%s", "years", key.Format("2006"))
	return DashboardCache.GetListItems(ctx, USER_INCREASE_BIND_BIKE, keyStr)
}

// 没有绑定车辆的缓存
func (e *userUnbindBike) AddOneDay(ctx context.Context, key time.Time, count int64) (int64, error) {
	ketStr := key.Format("2006-01")
	return DashboardCache.AddOneDayCount(ctx, USER_INCREASE_UNBIND_BIKE, ketStr, count)

}
func (e *userUnbindBike) GetOneDay(ctx context.Context, key time.Time) (int64, error) {
	keyStr := key.Format("2006-01")
	dayOfMonth := key.Day()
	// 月份天数都是从1开始的，list从0开始
	return DashboardCache.GetOneDayCount(ctx, USER_INCREASE_UNBIND_BIKE, keyStr, int64(dayOfMonth-1))
}

func (e *userUnbindBike) AddThirtyDays(ctx context.Context, key time.Time, counts []int64) (int64, error) {
	keyStr := key.Format("2006-01")
	return DashboardCache.AddBatch(ctx, USER_INCREASE_UNBIND_BIKE, keyStr, counts...)
}

// GetThirtyDays 获取当前月份所有的天数数据
func (e *userUnbindBike) GetThirtyDays(ctx context.Context, key time.Time) ([]int64, error) {
	keyStr := key.Format("2006-01")
	return DashboardCache.GetListItems(ctx, USER_INCREASE_UNBIND_BIKE, keyStr)
}

// AddTwelveMonths 获取当前年所有月份数据
func (e *userUnbindBike) AddTwelveMonths(ctx context.Context, key time.Time, counts []int64) (int64, error) {
	keyStr := key.Format("2006")
	return DashboardCache.AddBatch(ctx, USER_INCREASE_UNBIND_BIKE, keyStr, counts...)
}

// GetTwelveMonths 获取当前年所有月份数据
func (e *userUnbindBike) GetTwelveMonths(ctx context.Context, key time.Time) ([]int64, error) {
	keyStr := key.Format("2006")
	return DashboardCache.GetListItems(ctx, USER_INCREASE_UNBIND_BIKE, keyStr)
}

// AddFiveYears 获取当前年所有月份数据
func (e *userUnbindBike) AddFiveYears(ctx context.Context, key time.Time, counts []int64) (int64, error) {
	// 前面4年的数据是已经确定的，年度数据实时计算redis内部缓存数据
	// 往前推4年
	keyStr := fmt.Sprintf("%s:%s", "years", key.Format("2006"))
	return DashboardCache.AddBatch(ctx, USER_INCREASE_UNBIND_BIKE, keyStr, counts...)
}
func (e *userUnbindBike) GetFiveYears(ctx context.Context, key time.Time) ([]int64, error) {
	// 按照从远到近依次返回数据，不包含今年的数据，今年数据实时计算
	keyStr := fmt.Sprintf("%s:%s", "years", key.Format("2006"))
	return DashboardCache.GetListItems(ctx, USER_INCREASE_UNBIND_BIKE, keyStr)
}

// 用户投诉
func (e *userComplain) AddOneDay(ctx context.Context, key time.Time, count int64) (int64, error) {
	ketStr := key.Format("2006-01")
	return DashboardCache.AddOneDayCount(ctx, USER_COMPLAIN, ketStr, count)

}
func (e *userComplain) GetOneDay(ctx context.Context, key time.Time) (int64, error) {
	keyStr := key.Format("2006-01")
	dayOfMonth := key.Day()
	// 月份天数都是从1开始的，list从0开始
	return DashboardCache.GetOneDayCount(ctx, USER_COMPLAIN, keyStr, int64(dayOfMonth-1))
}

func (e *userComplain) AddThirtyDays(ctx context.Context, key time.Time, counts []int64) (int64, error) {
	keyStr := key.Format("2006-01")
	return DashboardCache.AddBatch(ctx, USER_COMPLAIN, keyStr, counts...)
}

// GetThirtyDays 获取当前月份所有的天数数据
func (e *userComplain) GetThirtyDays(ctx context.Context, key time.Time) ([]int64, error) {
	keyStr := key.Format("2006-01")
	return DashboardCache.GetListItems(ctx, USER_COMPLAIN, keyStr)
}

// AddTwelveMonths 获取当前年所有月份数据
func (e *userComplain) AddTwelveMonths(ctx context.Context, key time.Time, counts []int64) (int64, error) {
	keyStr := key.Format("2006")
	return DashboardCache.AddBatch(ctx, USER_COMPLAIN, keyStr, counts...)
}

// GetTwelveMonths 获取当前年所有月份数据
func (e *userComplain) GetTwelveMonths(ctx context.Context, key time.Time) ([]int64, error) {
	keyStr := key.Format("2006")
	return DashboardCache.GetListItems(ctx, USER_COMPLAIN, keyStr)
}

// AddFiveYears 获取当前年所有月份数据
func (e *userComplain) AddFiveYears(ctx context.Context, key time.Time, counts []int64) (int64, error) {
	// 前面4年的数据是已经确定的，年度数据实时计算redis内部缓存数据
	// 往前推4年
	keyStr := fmt.Sprintf("%s:%s", "years", key.Format("2006"))
	return DashboardCache.AddBatch(ctx, USER_COMPLAIN, keyStr, counts...)
}
func (e *userComplain) GetFiveYears(ctx context.Context, key time.Time) ([]int64, error) {
	// 按照从远到近依次返回数据，不包含今年的数据，今年数据实时计算
	keyStr := fmt.Sprintf("%s:%s", "years", key.Format("2006"))
	return DashboardCache.GetListItems(ctx, USER_COMPLAIN, keyStr)
}

// 用户用户新增
func (e *user) AddOneDay(ctx context.Context, key time.Time, count int64) (int64, error) {
	ketStr := key.Format("2006-01")
	return DashboardCache.AddOneDayCount(ctx, USER_INCREASE, ketStr, count)

}
func (e *user) GetOneDay(ctx context.Context, key time.Time) (int64, error) {
	keyStr := key.Format("2006-01")
	dayOfMonth := key.Day()
	// 月份天数都是从1开始的，list从0开始
	return DashboardCache.GetOneDayCount(ctx, USER_INCREASE, keyStr, int64(dayOfMonth-1))
}

func (e *user) AddThirtyDays(ctx context.Context, key time.Time, counts []int64) (int64, error) {
	keyStr := key.Format("2006-01")
	return DashboardCache.AddBatch(ctx, USER_INCREASE, keyStr, counts...)
}

// GetThirtyDays 获取当前月份所有的天数数据
func (e *user) GetThirtyDays(ctx context.Context, key time.Time) ([]int64, error) {
	keyStr := key.Format("2006-01")
	return DashboardCache.GetListItems(ctx, USER_INCREASE, keyStr)
}

// AddTwelveMonths 获取当前年所有月份数据
func (e *user) AddTwelveMonths(ctx context.Context, key time.Time, counts []int64) (int64, error) {
	keyStr := key.Format("2006")
	return DashboardCache.AddBatch(ctx, USER_INCREASE, keyStr, counts...)
}

// GetTwelveMonths 获取当前年所有月份数据
func (e *user) GetTwelveMonths(ctx context.Context, key time.Time) ([]int64, error) {
	keyStr := key.Format("2006")
	return DashboardCache.GetListItems(ctx, USER_INCREASE, keyStr)
}

// AddFiveYears 获取当前年所有月份数据
func (e *user) AddFiveYears(ctx context.Context, key time.Time, counts []int64) (int64, error) {
	// 前面4年的数据是已经确定的，年度数据实时计算redis内部缓存数据
	// 往前推4年
	keyStr := fmt.Sprintf("%s:%s", "years", key.Format("2006"))
	return DashboardCache.AddBatch(ctx, USER_INCREASE, keyStr, counts...)
}
func (e *user) GetFiveYears(ctx context.Context, key time.Time) ([]int64, error) {
	// 按照从远到近依次返回数据，不包含今年的数据，今年数据实时计算
	keyStr := fmt.Sprintf("%s:%s", "years", key.Format("2006"))
	return DashboardCache.GetListItems(ctx, USER_INCREASE, keyStr)
}

func (e *userActive) AddOneDay(ctx context.Context, key time.Time, count int64) (int64, error) {

	return 0, nil

}

func (e *userActive) GetOneDay(ctx context.Context, key time.Time) (int64, error) {

	// 月份天数都是从1开始的，list从0开始
	return 0, nil
}

func (e *userActive) AddThirtyDays(ctx context.Context, key time.Time, counts []int64) (int64, error) {

	return 0, nil
}

// GetThirtyDays 获取当前月份所有的天数数据
func (e *userActive) GetThirtyDays(ctx context.Context, key time.Time) ([]int64, error) {

	return []int64{}, nil
}

// AddTwelveMonths 获取当前年所有月份数据
func (e *userActive) AddTwelveMonths(ctx context.Context, key time.Time, counts []int64) (int64, error) {

	return 0, nil
}

// GetTwelveMonths 获取当前年所有月份数据
func (e *userActive) GetTwelveMonths(ctx context.Context, key time.Time) ([]int64, error) {

	return []int64{}, nil
}

// AddFiveYears 获取当前年所有月份数据
func (e *userActive) AddFiveYears(ctx context.Context, key time.Time, counts []int64) (int64, error) {
	// 前面4年的数据是已经确定的，年度数据实时计算redis内部缓存数据
	// 往前推4年
	keyStr := fmt.Sprintf("%s:%s", "years", key.Format("2006"))
	return DashboardCache.AddBatch(ctx, USER_INCREASE_BIND_BIKE, keyStr, counts...)
}

func (e *userActive) GetFiveYears(ctx context.Context, key time.Time) ([]int64, error) {
	// 按照从远到近依次返回数据，不包含今年的数据，今年数据实时计算
	keyStr := fmt.Sprintf("%s:%s", "years", key.Format("2006"))
	return DashboardCache.GetListItems(ctx, USER_INCREASE_BIND_BIKE, keyStr)
}
